<?php

if (!defined('BASEPATH'))
    exit('No direct script access
allowed');
if (!function_exists('callProc')) {

    class DB_Result {

        private $_result;
        private $_message;

        public function __get($name) {
            switch ($name) {
                case 'RESULT':
                    return $this->_result;
                    break;

                case 'MESSAGE':
                    return $this->_message;
                    break;

                default:
                    return '';
                    break;
            }
        }

        public function __set($name, $value) {
            switch ($name) {
                case 'RESULT':
                    $this->_result = $value;
                    break;

                case 'MESSAGE':
                    $this->_message = $value;
                    break;

                default:
                    break;
            }
        }

    }

    function callProc($db, $shema, $procedure, $datas) {
        $request = 'SELECT ';
        $request .= '"' . strtoupper($db) . '".';
        $request .= '"' . strtoupper($shema) . '".';
        $request .= '"' . strtoupper($procedure) . '"';
        $request .= '(' . implode(', ', $datas) . ')';

        $CI = get_instance();
        $CI->db = $CI->load->database('DB_PLASTPROD', true);
        $tmp = $CI->db->query($request)->result();

        // Formatage du result.
        $tmpResult = explode(',', str_replace(array('(', ')', '"'), '', $tmp[0]->$procedure));
        $result = new DB_Result();
        $result->RESULT = $tmpResult[0];
        $result->MESSAGE = $tmpResult[1];

        return $result;
    }

}
?>